<%--
  Created by IntelliJ IDEA.
  User: 莫
  Date: 2018/1/4
  Time: 18:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="css/bootstrap-datetimepicker.min.css" media="screen">
    <script src="js/jquery-2.1.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>

    <style>
        .col-center-block {
            float: none;
            display: block;
            margin-left: auto;
            margin-right: auto;
        }

        .text-col {
            padding-top: 40px;
        }
    </style>
</head>
<body style="font-size: 19px">
<!--头-->
<nav id="top">
    <div class="container">
        <div class="row">
            <div class="col-md-6">
                <strong>Welcome to Us!</strong>
            </div>
            <div class="col-md-6">
                <ul class="list-inline top-link link">
                    <li><a href="login.jsp"><i class="fa fa-home"></i>Login</a></li>
                    <li><a href="register.jsp"><i class="fa fa-comments"></i>Register</a></li>
                    <li><a href="#"><i class="fa fa-question-circle"></i>FAQ</a></li>
                </ul>
            </div>
        </div>
    </div>
</nav>
<div class="container">
    <div class="row headline">  
        <div class="col-xs-6 col-md-4" id="head" style="text-align:center">  

        </div>
    </div>
    <div class="row name_uptime">
        <div class="col-xs-6 col-md-4" id="name_time" style="text-align:center">

        </div>
    </div>
</div>
<div class="container text-col">
    <div class="row content">
        <div class="col-xs-6 col-md-4" id="content" style="word-break: break-all;word-wrap: break-word;">

        </div>
    </div>
</div>
<script language='javascript'>
    var xmlhttp;
    // function getUrlParams(name)
    // {
    //     var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    //     var r = window.location.search.substr(1).match(reg);
    //     if (r != null) return r[2]; return "";
    // }
    // $(function(){
    //     var name = getUrlParams("Title");
    //     alert(name)
    // });

    window.onload = function test() {

        var result = "<%=request.getParameter("name")%>";
        if (result == "")result=getUrlParams("Title");


        xmlhttp = new XMLHttpRequest();
        xmlhttp.open("POST", "FindNews_head", false);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.send("Headline=" + result);

        var newss ='';
        newss = xmlhttp.responseText.toString();
        console.log(newss);
        var news = JSON.parse(newss);
        console.log(news);
        if (news.Result == "Success") {
            NewsHeadline = news.NewsContents.Headline;
            NewsName = news.NewsContents.Name;
            NewsContent = news.NewsContents.Content;
            NewsUpTime = news.NewsContents.UpTime;


            var oHead = document.getElementById("head");
            var newNode = document.createElement("h1");
            var hr = document.createElement("hr");
            newNode.innerHTML = NewsHeadline + "<br>";
            hr.style = "border-top: 2px solid #272424;"
            oHead.appendChild(newNode);
            oHead.appendChild(hr);

                    var oName_Time = document.getElementById("name_time");
            var name_time = document.createElement("h3");
            var name = NewsName;
            var time = NewsUpTime;
            name_time.innerHTML = "作者:" + name + "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp时间：" + time;
            oName_Time.appendChild(name_time);

            var content = document.getElementById("content");
            var text = document.createElement("p");
            var txt = NewsContent;
            text.innerHTML = txt;
            content.appendChild(text);

        }
    }
</script>
</body>
</html>
